package com.genesis.web.controller;


import com.genesis.mall.common.Result;
import com.genesis.mall.entity.SmsFlashPromotionSession;
import com.genesis.mall.service.ISmsFlashPromotionSessionService;
import com.genesis.mall.vo.SmsFlashPromotionSessionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 限时购场次表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private ISmsFlashPromotionSessionService flashPromotionSessionService;

    /**
     * 添加场次
     *
     * @param flashPromotionSession
     * @return
     */
    @PostMapping("/create")
    public Result create(@RequestBody SmsFlashPromotionSession flashPromotionSession) {
       /* flashPromotionSession.setStartTime(flashPromotionSession.getStartTime().(0,10));
        flashPromotionSession.setEndTime(flashPromotionSession.getStartTime().substring(0,10));*/
        flashPromotionSessionService.save(flashPromotionSession);
        return Result.success();
    }

    /**
     * 删除场次
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        flashPromotionSessionService.removeById(id);
        return Result.success("delete成功");
    }

    /**
     * 获取全部场次
     *
     * @return
     */
    @GetMapping("/list")
    public Result list() {
        List<SmsFlashPromotionSession> list = flashPromotionSessionService.list();
        return Result.success(list);
    }

    /**
     * 获取全部可选场次和数量
     *
     * @param flashPromotionId
     * @return
     */
    @GetMapping("/selectList")
    public Result selectList(Integer flashPromotionId) {
        List<SmsFlashPromotionSessionVo> list = flashPromotionSessionService.selectList(flashPromotionId);
        return Result.success(list);
    }

    /**
     * 修改启用状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public Result updateStatus(@PathVariable Integer id, @RequestParam(required = false) Integer status) {
        flashPromotionSessionService.updateStatus(id, status);
        return Result.success();
    }

    /**
     * 修改场次
     *
     * @param id
     * @param flashPromotionSession
     * @return
     */
    @PostMapping("/update/{id}")
    public Result update(@PathVariable Integer id, @RequestBody SmsFlashPromotionSession flashPromotionSession) {
        flashPromotionSession.setId((long) id);
        flashPromotionSessionService.updateById(flashPromotionSession);
        return Result.success();
    }

    /**
     * 获取场次详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getSessionId(@PathVariable Integer id) {
        SmsFlashPromotionSession flashPromotionSession = flashPromotionSessionService.getById(id);
        return Result.success(flashPromotionSession);
    }
}
